﻿using Admin.NET.Application.Const;
using Admin.NET.Application.Entity;
using System.Collections.Generic;

namespace Admin.NET.Application;
/// <summary>
/// 标签map服务
/// </summary>
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
public class car_tagmapService : IDynamicApiController, ITransient
{
    private readonly SqlSugarRepository<car_tagmap> _rep;
    public car_tagmapService(SqlSugarRepository<car_tagmap> rep)
    {
        _rep = rep;
    }

    /// <summary>
    /// 分页查询标签map
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Page")]
    public async Task<SqlSugarPagedList<car_tagmapOutput>> Page(car_tagmapInput input)
    {
        var query= _rep.AsQueryable()
                    .WhereIF(input.Id>0, u => u.Id == input.Id)
                    .WhereIF(input.caseid>0, u => u.caseid == input.caseid)
                    .WhereIF(input.tagid>0, u => u.tagid == input.tagid)

                    .Select<car_tagmapOutput>()
;
        query = query.OrderBuilder(input);
        return await query.ToPagedListAsync(input.Page, input.PageSize);
    }

    /// <summary>
    /// 增加标签map
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Add")]
    public async Task Add(Addcar_tagmapInput input)
    {
        var entity = input.Adapt<car_tagmap>();
        await _rep.InsertAsync(entity);
    }

    /// <summary>
    /// 删除标签map
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    //[HttpPost]
    //[ApiDescriptionSettings(Name = "Delete")]
    //public async Task Delete(Deletecar_tagmapInput input)
    //{
    //    await _rep.FakeDeleteAsync(entity);   //假删除
    //}

    /// <summary>
    /// 更新标签map
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Update")]
    public async Task Update(Updatecar_tagmapInput input)
    {
        var entity = input.Adapt<car_tagmap>();
        await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
    }

    /// <summary>
    /// 获取标签map
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    //[HttpGet]
    //[ApiDescriptionSettings(Name = "Detail")]
    //public async Task<car_tagmap> Get([FromQuery] QueryByIdcar_tagmapInput input)
    //{
    //}

    /// <summary>
    /// 获取标签map列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "List")]
    public async Task<List<car_tagmapOutput>> List([FromQuery] car_tagmapInput input)
    {
        return await _rep.AsQueryable().Select<car_tagmapOutput>().ToListAsync();
    }





}

